Open
Conversation
Remove workflow.md from git and ignore documentation files stop commiting docs.md Simplify GitHub Actions workflow to use anchor test
e2d10e6 to
e6c70a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧪 Comprehensive Test Suite for CBMM Protocol
Overview
This PR adds a complete test suite for the CBMM protocol, including unit tests, integration tests, and mathematical verification of all whitepaper formulas.
📊 Test Coverage Summary
New Tests Added: 62 total tests
Coverage by Instruction:
initialize_central_statecreate_poolinitialize_virtual_token_accountclose_virtual_token_accountbuy_virtual_tokenburn_virtual_tokensell_virtual_tokenclose_user_burn_allowance🎯 Key Features
1. Whitepaper Formula Verification
All mathematical formulas from
main.mdare tested with exact calculations:Buy Instruction:
k = (A + V) * Bb = (B * ΔA) / (A + V + ΔA)P = (A + V) / BBurn Instruction:
V₂ = V₁ * (B₁ - y) / B₁(P₂ - P₁) / P₁ = xy / (B(B - x - y))ΔA = min(ΔV, F)L = ΔV - ΔA2. Integration Tests
Test Categories:
Core Workflows (9 tests)
Failure Tests (4 tests)
Idempotency Tests (4 tests)
Rent Exemption Tests (3 tests)
Multi-User Scenarios (1 test)
3. Unit Tests
Best Practices:
📁 Files Modified
New Files Created:
bcpmm/programs/cbmm/tests/integration_basic.rs(1268 lines).vscode/settings.jsontest-helpersfeatureModified Files:
bcpmm/programs/cbmm/src/instructions/initialize_central_state.rsbcpmm/programs/cbmm/src/instructions/create_pool.rsbcpmm/programs/cbmm/src/instructions/initialize_virtual_token_account.rsbcpmm/programs/cbmm/src/instructions/close_virtual_token_account.rsbcpmm/programs/cbmm/src/instructions/buy_virtual_token.rsbcpmm/programs/cbmm/src/instructions/burn_virtual_token.rsbcpmm/programs/cbmm/src/instructions/close_user_burn_allowance.rsbcpmm/programs/cbmm/src/test_utils/test_runner.rsget_pool_data()- Retrieve pool stateget_vta_data()- Retrieve VTA statecalculate_expected_buy_output()- Buy formulacalculate_expected_virtual_reserve_after_burn()- Burn formulacalculate_price()- Price formulacalculate_invariant()- Invariant calculationsell_virtual_token()- Sell instructionmint_to()to auto-create ATAsbcpmm/programs/cbmm/Cargo.tomltest-helpersfeature flagbcpmm/programs/cbmm/src/lib.rstest_utilsmodule withtest-helpersfeaturebcpmm/programs/cbmm/src/test_utils/mod.rs🧮 Mathematical Verification
Canonical Test Vectors
All tests use the same initial state for consistency:
Example: Buy 100K Tokens
(Note: The exact calculation accounts for integer division rounding)
🚀 How to Run Tests
Run All Tests:
Run Specific Tests:
IDE Configuration:
To fix rust-analyzer errors in integration tests, ensure
.vscode/settings.jsonexists with:{ "rust-analyzer.cargo.features": ["test-helpers"], "rust-analyzer.checkOnSave.command": "clippy" }✅ Test Results
All tests passing:
🔒 Security & Quality Improvements
Authorization Testing
Constraint Verification
Economic Invariants
k = (A + V) * Bpreserved or increasesRent Exemption
🧪 Test Philosophy
Unit Tests (Mock-Based):
Integration Tests (Real Instructions):
Both are needed - they complement each other!
🔄 Changes Required for Review
None - Ready to Merge!
All tests passing, code is clean, and documentation is comprehensive.
📝 Notes for Reviewer
Feature Flag: Integration tests require
--features test-helpersto compile. This is intentional to keep the main program binary lean.Test Count: 62 new tests is a lot, but each one tests a specific scenario or constraint. Review by category (see "Test Coverage Summary" above).
Whitepaper Formulas: All mathematical tests match the formulas in
main.md. Cross-reference if needed.Code Quality: All tests follow Rust best practices:
Performance: All tests run in < 10 seconds total: